using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

namespace ProductExpirationAssistant
{
    /// <summary>下架生产日期查询记录</summary>
    public class OffShelfProductionDateQuery
    {
        /// <summary>保质期</summary>
        public QualityGuaranteePeriod qualityGuaranteePeriod { get; set; }
        /// <summary>提前下架天数</summary>
        public int daysInAdvance { get; set; }

        public OffShelfProductionDateQuery()
        {
            qualityGuaranteePeriod = new QualityGuaranteePeriod();
        }

        /// <summary>计算下架生产日期</summary>
        public DateTime CalOffShelfProductionDate()
        {
            var date = DataManager.ins.curDate;

            switch (qualityGuaranteePeriod.unit)
            {
                case DateUnit.Day:
                    {
                        date = date.AddDays(-qualityGuaranteePeriod.num);
                        break;
                    }
                case DateUnit.Month:
                    {
                        date = date.AddMonths(-qualityGuaranteePeriod.num);
                        break;
                    }
                case DateUnit.Year:
                    {
                        date = date.AddYears(-qualityGuaranteePeriod.num);
                        break;
                    }
            }

            return date.AddDays(1 + daysInAdvance);
        }

        /// <summary>计算过期生产日期</summary>
        public DateTime CalExpiredProductionDate()
        {
            return CalOffShelfProductionDate().AddDays(-daysInAdvance);
        }

        public bool Compare(OffShelfProductionDateQuery query)
        {
            // 比较顺序：保质期日期所用的单位>保质期数>提前下架天数
            if (qualityGuaranteePeriod.unit == query.qualityGuaranteePeriod.unit)
            {
                if (qualityGuaranteePeriod.num == query.qualityGuaranteePeriod.num)
                {
                    return daysInAdvance > query.daysInAdvance;
                }
                else
                {
                    return qualityGuaranteePeriod.num > query.qualityGuaranteePeriod.num;
                }
            }
            else
            {
                return qualityGuaranteePeriod.unit > query.qualityGuaranteePeriod.unit;
            }
        }
    }
}